﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameSDK.Board;
using GameSDK.Events;

namespace GameSDK.Player
{
    /// <summary>
    /// Standard classe for Player Description
    /// </summary>
    public abstract class StdPlayer
    {
        #region Attributes
        /// <summary>
        /// Boatd associated within the player
        /// </summary>
        private StdBoard _board;
        public StdBoard Board
        {
            get { return _board; }
            set {
                if (_board != null)
                {
                    _board.PlayerMove -= new PlayerMovedEventHandler(DoPlayMove);
                }
                _board = value;
                _board.PlayerMove += new PlayerMovedEventHandler(DoPlayMove);
            }
        }

        /// <summary>
        /// Game Player Id
        /// </summary>
        private int _gamePlayerId;
        public int GamePlayerId { 
            get {return _gamePlayerId;}
            set { _gamePlayerId = value; } 
        }

        /// <summary>
        /// Strategy used by the player
        /// </summary>
        private IStdStrategy _strategy;
        public IStdStrategy Strategy {
            get { return _strategy; }
            set { _strategy = value; }
        }

        #endregion

        #region Constructor
        /// <summary>
        /// Default Constructor
        /// </summary>
        public StdPlayer()
        {
            _gamePlayerId = -1;
            _strategy = null;
            _board = null;
        }
        /// <summary>
        /// Constuctor within a Board
        /// </summary>
        /// <param name="board"></param>
        public StdPlayer(StdBoard board) : this()
        {
            Board = board;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Player play a move according to its Strategy
        /// </summary>
        public void NextMove()
        {
            if (_strategy != null)
            {
                _strategy.DoMove();
            }
        }

        #endregion

        #region Events
        /// <summary>
        /// DoPlayMove needs to be instanciated. It is the methods associated within a Move
        /// </summary>
        /// <param name="sender">Sender that send the event</param>
        /// <param name="MoveArgs">MoveEventArgs associated</param>
        public abstract void DoPlayMove(object sender, MoveEventArgs MoveArgs);

        #endregion
    }
}
